package com.security.web.filter;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;

/**
 * Filter只能拿到Http的请求和响应，不能拿到是那个控制器、方法来处理的信息
 *
 * @author roger
 * @email 190642964@qq.com
 * @create 2017-11-01 17:09
 **/
//@Component
public class TimeFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("TimeFilter init ");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("TimeFilter start ");

        long start = System.currentTimeMillis();
        chain.doFilter(request, response);
        long finish = System.currentTimeMillis();
        System.out.println("总共耗时 : " + (finish - start));
        System.out.println("TimeFilter finish ");
    }

    @Override
    public void destroy() {
        System.out.println("TimeFilter destroy ");
    }
}
